package com.yangwp.doutu.controller;

import com.yangwp.doutu.Utils.MapUtil;
import com.yangwp.doutu.enums.RespEnum;
import com.yangwp.doutu.service.DoutuUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    private DoutuUserService doutuUserService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> save(String userId, String userName, String head){
        try {
            if(head == null){
                head = "3f74225647b9f919!400x400_big.jpg";
            }
            if(StringUtils.isBlank(userId) || StringUtils.isBlank(userName) || StringUtils.isBlank(head)){
                return MapUtil.getMap(RespEnum.MISSING_PARAM);
            }

            if(doutuUserService.addUser(userName, userId, head)){
                return MapUtil.getMap(RespEnum.OK);
            }
        }catch (Exception e){
            System.out.println("ff");
        }
        return MapUtil.getMap(RespEnum.SERVER_FAIL);
    }

}
